/////////////////////////////////////////////////////////////////////////////
// Name:        generalpanel.cpp
// Purpose:     
// Author:      Brant Young
// Modified by: 
// Created:     Wed Jun 20 23:05:28 2007
// RCS-ID:      
// Copyright:   (C) Victsoft 2007
// Licence:     GPL 2.0
/////////////////////////////////////////////////////////////////////////////

#include "wx/wx.h"
#include "generalpanel.h"
#include "cfgmgr.h"


/*!
 * GeneralPanel constructors
 */

GeneralPanel::GeneralPanel(wxWindow* p_parent) : wxPanel(p_parent, ID_GENERAL_PANEL, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER|wxTAB_TRAVERSAL)
{   
////@begin GeneralPanel content construction
	
    p_root_sizer = new wxBoxSizer(wxVERTICAL);
    this->SetSizer(p_root_sizer);

    p_common_sizer_stc = new wxStaticBox(this, wxID_STATIC, _("Common"));
    p_common_sizer = new wxStaticBoxSizer(p_common_sizer_stc, wxVERTICAL);
    p_root_sizer->Add(p_common_sizer, 1, wxGROW|wxALL, 5);

    p_lang_sizer = new wxBoxSizer(wxHORIZONTAL);
    p_common_sizer->Add(p_lang_sizer, 0, wxGROW|wxALL, 5);

    p_lang_stc = new wxStaticText( this, wxID_STATIC, _("Interface Language:"), wxDefaultPosition, wxDefaultSize, 0 );
    p_lang_sizer->Add(p_lang_stc, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxArrayString lang_cboxStrings;
    lang_cboxStrings.Add(_T("English"));
    lang_cboxStrings.Add(_T("Simplified Chinese"));
    p_lang_cbox = new wxComboBox( this, ID_LANG_CBOX, _T(""), wxDefaultPosition, wxDefaultSize, lang_cboxStrings, wxCB_READONLY );
    p_lang_sizer->Add(p_lang_cbox, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    p_minimize_chkbox = new wxCheckBox( this, ID_MINIMIZE_CHKBOX, _("Minimized main window to Notification Area when DaoDict starts."), wxDefaultPosition, wxDefaultSize, 0 );
    p_minimize_chkbox->SetValue(false);
    p_common_sizer->Add(p_minimize_chkbox, 0, wxGROW|wxALL, 5);

    p_enable_sound_chkbox = new wxCheckBox( this, ID_ENABLE_SOUND_CHKBOX, _("Enable sound event."), wxDefaultPosition, wxDefaultSize, 0 );
    p_enable_sound_chkbox->SetValue(false);
    p_common_sizer->Add(p_enable_sound_chkbox, 0, wxGROW|wxALL, 5);

    p_float_wnd_sizer_stc = new wxStaticBox(this, wxID_STATIC, _("Floating window"));
    p_float_wnd_sizer = new wxStaticBoxSizer(p_float_wnd_sizer_stc, wxVERTICAL);
    p_root_sizer->Add(p_float_wnd_sizer, 1, wxGROW|wxALL, 5);

    p_show_float_wnd_chkbox = new wxCheckBox( this, ID_SHOW_FLOAT_WND_CHKBOX, _("Only show while modifier key is being pressed."), wxDefaultPosition, wxDefaultSize, 0 );
    p_show_float_wnd_chkbox->SetValue(false);
    p_float_wnd_sizer->Add(p_show_float_wnd_chkbox, 0, wxGROW|wxALL, 5);

    p_hide_float_wnd_chkbox = new wxCheckBox( this, ID_HIDE_FLOAT_WND_CHKBOX, _("Hide floating window after modifier key released."), wxDefaultPosition, wxDefaultSize, 0 );
    p_hide_float_wnd_chkbox->SetValue(false);
    p_float_wnd_sizer->Add(p_hide_float_wnd_chkbox, 0, wxGROW|wxALL, 5);

    p_key_sizer = new wxBoxSizer(wxHORIZONTAL);
    p_float_wnd_sizer->Add(p_key_sizer, 0, wxGROW|wxALL, 5);

    p_key_stc = new wxStaticText( this, wxID_STATIC, _("Modifier key : "), wxDefaultPosition, wxDefaultSize, 0 );
    p_key_sizer->Add(p_key_stc, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

    wxArrayString key_cboxStrings;
    key_cboxStrings.Add(_("Alt"));
    key_cboxStrings.Add(_("Ctrl"));
    key_cboxStrings.Add(_("Shift"));
    key_cboxStrings.Add(_("Ctrl+Alt"));
    p_key_cbox = new wxComboBox( this, ID_KEY_CBOX, _T(""), wxDefaultPosition, wxDefaultSize, key_cboxStrings, wxCB_READONLY );
    p_key_sizer->Add(p_key_cbox, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);

////@end GeneralPanel content construction
    
    _init_cfg();
    Fit();
}


/*!
 * GeneralPanel destructor
 */

GeneralPanel::~GeneralPanel()
{
////@begin GeneralPanel destruction
////@end GeneralPanel destruction
}

void GeneralPanel::_init_cfg() {
	wxString str;
	bool flag;
	
	ConfigManager& cfg_mgr = ConfigManager::get();
	
	str = cfg_mgr.Read(_T("/Common/InterfaceLanguage"));
	p_lang_cbox->SetValue(str);
	
	cfg_mgr.Read(_T("/Common/MinWhenStart"),&flag, false);
	p_minimize_chkbox->SetValue(flag);
	
	cfg_mgr.Read(_T("/Common/EnableSoundEvent"),&flag, false);
	p_enable_sound_chkbox->SetValue(flag);
	
	cfg_mgr.Read(_T("/FloatWindow/OnlyShowWhenModKeyPressed"),&flag, true);
	p_show_float_wnd_chkbox->SetValue(flag);
	
	cfg_mgr.Read(_T("/FloatWindow/HideWhenModKeyReleased"),&flag, true);
	p_hide_float_wnd_chkbox->SetValue(flag);
	
	str = cfg_mgr.Read(_T("/FloatWindow/ModifierKey"));
	p_key_cbox->SetValue(str);
}

bool GeneralPanel::set_cfg() {
	ConfigManager& cfg_mgr = ConfigManager::get();

	cfg_mgr.Write(_T("/Common/MinWhenStart"), p_minimize_chkbox->IsChecked());
	cfg_mgr.Write(_T("/Common/EnableSoundEvent"), p_enable_sound_chkbox->IsChecked());
	cfg_mgr.Write(_T("/Common/InterfaceLanguage"), p_lang_cbox->GetValue());
	cfg_mgr.Write(_T("/Common/OnlyShowWhenModKeyPressed"), p_show_float_wnd_chkbox->IsChecked());
	cfg_mgr.Write(_T("/Common/HideWhenModKeyReleased"), p_hide_float_wnd_chkbox->IsChecked());
	cfg_mgr.Write(_T("/FloatWindow/ModifierKey"), p_key_cbox->GetValue());
	
	return true;
}

